﻿using Atha.Contracts;
using IronScheme.Hosting;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;

namespace Atha.Languages.IronSchemex
{
	public sealed class SchemeTestRunContext : ScriptTestRunContextBase
	{
		public SchemeTestRunContext(string name, string script)
			: base(name, script)
		{
		}

		protected override void OnExecute(string script, ITestRunResultBuilder testRunResultBuilder)
		{
			ScriptEnvironmentSetup setup = new ScriptEnvironmentSetup(true);
			ScriptDomainManager manager;
			ScriptDomainManager.TryCreateLocal(setup, out manager);

			var lang = manager.GetLanguageProvider(typeof(IronSchemeLanguageProvider));
			//var lang = ScriptEnvironment.GetEnvironment().GetLanguageProvider(typeof(IronSchemeLanguageProvider));

			//var lang = ScriptDomainManager.CurrentManager.GetLanguageProvider(typeof(IronSchemeLanguageProvider));

			var engine = lang.GetEngine();

			engine.Execute(script);
		}
	}
}